import React from 'react'

import {Route,Switch ,Redirect} from 'react-router-dom'
import {adminRouter} from './routes'
import {Frame} from './components'
import { connect } from 'react-redux'
const menu=adminRouter.filter(item=>item.isNav===true)

  class App extends React.Component{
    constructor(){
        super()
        this.state={
        
        }
    }
    componentDidMount(){
      
        
    }
    render(){
    
      
       return (
     <Frame menu={menu}>

<Switch>
        {
          adminRouter.map((route)=>{
            return (
              <Route 
              key={route.pathname}
               path={route.pathname}
               exact={route.exact}
              
                render={(routeProps)=>{
                
              
                 return route.roles.includes(this.props.role)? <route.component {...routeProps}/> :<Redirect to="/admin/authority" />
              }} />

            )
          })
        }

        <Redirect to={adminRouter[0].pathname}  from='/admin' exact />
        <Redirect to='/404'/>
       </Switch>


     </Frame>
     
     
        
        
      

       
    
      
  


   
       )
    }
}
const mapState = (state) => {


  return {
   role:state.Login.role
  }

}
export default connect(mapState)(App)

//配置路由按需加载  懒加载